package com.sean.findme.enjoy;

import com.sean.findme.FmActivityInfo;
import com.sean.findme.FmActivityMgrCtrller;
import com.sean.findme.R;
import com.sean.findme.dbentrys.EnjoyInfos;
import com.sean.findme.near.NearActivity;
import com.sean.findme.near.NearActivityGroup;

import android.app.Activity;
import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;

public class EnjoyActivityGroup extends ActivityGroup{

	LinearLayout container = null;
	EnjoyActivityManager enjoyActivityMgr = null;
	
	EnjoyInfos enjoyInfos = null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.groupactivity);
		
		enjoyActivityMgr = new EnjoyActivityManager(this);
		FmActivityMgrCtrller.getInstance(null).registerActivityMgr(getResources().getString(R.string.enjoy_tab), enjoyActivityMgr);
		
		enjoyInfos = new EnjoyInfos();
		
		container = (LinearLayout)findViewById(R.id.group_activity_layout);
		container.removeAllViews();
		
		Intent intent = new Intent( EnjoyActivityGroup.this, EnjoyMain.class);
		intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		
		enjoyActivityMgr.configFirstActivity(this);
		
		Window subActivity = this.getLocalActivityManager().startActivity("NearActivity", intent);
		View view = subActivity.getDecorView();
		container.addView(view);
		LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)view.getLayoutParams();
		params.width = LayoutParams.FILL_PARENT;
		params.height = LayoutParams.FILL_PARENT;
		view.setLayoutParams(params);
		
	}

	@Override
	public void onBackPressed() {
		if( EnjoyActivityManager.getInstance().getListActivityInfo().size() <= 1 )
			super.onBackPressed();
		else
		{
			EnjoyActivityManager.getInstance().getListActivityInfo().pop();
			FmActivityInfo info = EnjoyActivityManager.getInstance().getListActivityInfo().peek();
			EnjoyActivityManager.getInstance().JmpActivity(this.getCurrentActivity().getBaseContext(), info.getFromCls(), info.getActivityGroup(), info.getMap(), false);
		}
	}
	
	
	
	
	

}
